package com.xzl.servicehi.controller;

import com.xzl.servicehi.HiDTO;
import com.xzl.servicehi.domain.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HiController {
    @Value("${server.port}")
    String port;
    private static int count = 0;
    @Autowired
    UserMapper userMapper;

    @RequestMapping(value = "/hiya",method = RequestMethod.GET)
    public String home() {
        userMapper.selectByPrimaryKey(1);
        if (count % 3 == 0) {
            count++;
            throw new ArrayIndexOutOfBoundsException();
        }
        count++;
        return new String("hi ");
    }

    @RequestMapping(value = "/hip",method = RequestMethod.POST)
    public HiDTO hiya(@RequestBody HiDTO dto) {
        dto.setPwd(port);
        return dto;
    }
}
